import 'package:ft_reader/beans/book_item_bean.dart';
import 'package:ft_reader/blocs/base_bloc.dart';
import 'package:rxdart/rxdart.dart';

class BookListBloc extends BaseBloc {

  final _bookListFetcher = PublishSubject<List<BookItemBean>>();

  // 监听
  Observable<List<BookItemBean>> get bookListBloc => _bookListFetcher.stream;

  // async关键字声明该函数内部有代码需要延迟执行
  void fetchBookList(String sex, String kind, int page) async {
    // //await关键字声明运算为延迟执行
    List<BookItemBean> datas = await netApi.fetchBookList(sex, kind, page);
    if (!_bookListFetcher.isClosed) {
      // 添加
      _bookListFetcher.sink.add(datas);
    }
  }

  @override
  void dispose() {
    // TODO: implement dispose
    // 关闭
    super.dispose();_bookListFetcher?.close();

  }
}
